package com.swyc.osschat.Test.designMode.observer.impl;

import com.swyc.osschat.Test.designMode.observer.base.Observer;
import com.swyc.osschat.Test.designMode.observer.base.Subject;

import java.util.ArrayList;
import java.util.List;

/**
 * @description 具体主题：具体被观察者（微信公众号）
 * @Author: z156940l@outlook.com
 * @className SubscriptionSubject
 * @Date: 2022/6/28 9:24
 */
public class SubscriptionSubject implements Subject {
    //存储观察者
    private List<Observer> observerList = new ArrayList<>();

    @Override
    public void attach(Observer observer) {
        observerList.add(observer);
    }

    @Override
    public void detach(Observer observer) {
        observerList.remove(observer);
    }

    @Override
    public void update(String msg) {
        for (Observer observer : observerList){
            observer.update(msg);
        }
    }
}
